package com.liu.design.behavior.strategy.pay;

import java.util.HashMap;
import java.util.Map;

/**
 * @author LIU
 * @version 1.0
 * @date 2024/5/8 10:53
 * @description 上下文角色
 * 环境类(Context):持有抽象策略类的引用，用来操作策略的上下文环境。
 */
public class PayStrategyContext {
    public static final String ALI_PAY = "AliPay";
    public static final String JD_PAY = "JDPay";
    public static final String WECHAT_PAY = "WechatPay";
    public static final String UNION_PAY = "UnionPay";
    public static final String DEFAULT_PAY = ALI_PAY;

    private static final Map<String,Payment> strategies = new HashMap<>();

    static {
        strategies.put(ALI_PAY,new AliPay());
        strategies.put(JD_PAY,new JDPay());
        strategies.put(WECHAT_PAY,new WechatPay());
        strategies.put(UNION_PAY,new UnionPay());
    }

    public static Payment getPayment(String strategy){
        if (strategies.containsKey(strategy)){
           return strategies.get(strategy);
        }
        return strategies.get(DEFAULT_PAY);
    }
}
